<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<style type="text/css">
			div{
				margin: auto;
				text-align: center;
			}
		</style>
	</head>
	<body>
		<div id="div1">
			<select id="sid">
			<option value ="请选择大小" id="choice">请选择大小</option>
			<option value ="大" id="big">大</option>
			<option value ="小" id="small">小</option>
		    </select>
			<br>
			<img src="img/1.jpg" id="IMG">
		</div>
		<div id="">
			<button type="button" onabort="begin">开始</button>
		</div>
	</body>
	<script type="text/javascript">
	var play=true;
	var obj=document.getElementById('sid')
		function begin(){
			if(play){
				play=false;
				var iid=document.getElementById('IMG')
				var num=0;
				if(obj.value=='选择大小'){
					alert('请选择大小!')
				}else if(obj.value=='大' || obj.value=='小'){
					var a=setInterval(function(){
						var ranNum=RanNum();
						IMG.scr='img/'+ranNum+'.jpg';
						num++;
						if(num>10){
							clearInterval(a);
							choose(ranNum);
							play=true;
						}
					},300)
				}
			}
		}
		function choose(Num){
			var ChosId=document.getElementById('sid');
			var value=ChosId.options[ChosId.selectedIndex].value;
			if (value=='大') {
				if(Num>3){
				alert('你赢了')
				}else{
				alert('你输了')
				}
			} 
			if (value=='小') {
				if(Num<3{
				alert('你赢了')
				}else{
				alert('你输了')
				}
			} 
		}
		function RanNum(){
			while(true){
				var RanNum=Math.floor(Math.random()*6);
				if(RanNum!=0){
					return RanNum;
				}
			}
		}
	</script>
</html>
